from rest_framework import serializers
from myapp3.models import robox_info,project_info,Image,robox_infoTips,project_infoTips,robot_version
from myapp3.models import faq,faq_image
class RoboxSerializer(serializers.Serializer):

    id = serializers.IntegerField(read_only=True)
    use_people = serializers.CharField(max_length=100, allow_blank=True,required=False)
    delivery_time = serializers.CharField(max_length=100, allow_blank=True,required=False)
    robot_id = serializers.CharField(max_length=100)
    zeno_alias = serializers.CharField(max_length=100, allow_blank=True,required=False)
    robox_model = serializers.CharField(max_length=100, allow_blank=True,required=False)
    robot_model = serializers.CharField(max_length=100, allow_blank=True,required=False)
    sequence_sn = serializers.CharField(max_length=100, allow_blank=True,required=False)
    cmiit_id = serializers.CharField(max_length=100, allow_blank=True,required=False)
    usb_netcard_mac = serializers.CharField(max_length=100, allow_blank=True,required=False)
    lte_ssid = serializers.CharField(max_length=100, allow_blank=True,required=False)
    lte_passwd = serializers.CharField(max_length=100, allow_blank=True,required=False)
    sim_number = serializers.CharField(max_length=100, allow_blank=True,required=False)
    sim_active_time = serializers.CharField(max_length=100, allow_blank=True,required=False)
    sim_stop_time = serializers.CharField(max_length=100, allow_blank=True,required=False)
    used_record = serializers.CharField(max_length=100, allow_blank=True,required=False)
    used_charge = serializers.CharField(max_length=100, allow_blank=True,required=False)
    numbers = serializers.CharField(max_length=100, allow_blank=True,required=False)
    maintenance_record = serializers.CharField(max_length=100, allow_blank=True,required=False)
    other_info = serializers.CharField(max_length=100, allow_blank=True,required=False)

    def create(self, validated_data):
        """
        Create and return a new `Snippet` instance, given the validated data.
        """
        return robox_info.objects.create(**validated_data)

    def update(self, instance, validated_data):
        id = serializers.IntegerField(read_only=True)
        instance.delivery_time = validated_data.get('delivery_time', instance.delivery_time)
        instance.use_people = validated_data.get('use_people', instance.use_people)
        instance.robot_id = validated_data.get('robot_id', instance.robot_id)
        instance.zeno_alias = validated_data.get('zeno_alias', instance.zeno_alias)
        instance.robox_model = validated_data.get('robox_model', instance.robox_model)
        instance.robot_model =  validated_data.get('robot_model', instance.robot_model)
        instance.sequence_sn = validated_data.get('sequence_sn', instance.sequence_sn)
        instance.cmiit_id = validated_data.get('cmiit_id', instance.cmiit_id)
        instance.usb_netcard_mac = validated_data.get('usb_netcard_mac', instance.usb_netcard_mac)
        instance.lte_ssid = validated_data.get('lte_ssid', instance.lte_ssid)
        instance.lte_passwd = validated_data.get('lte_passwd', instance.lte_passwd)
        instance.sim_number = validated_data.get('sim_number', instance.sim_number)
        instance.sim_active_time =  validated_data.get('sim_active_time', instance.sim_active_time)
        instance.sim_stop_time = validated_data.get('sim_stop_time', instance.sim_stop_time)
        instance.used_record =  validated_data.get('used_record', instance.used_record)
        instance.used_charge =  validated_data.get('used_charge', instance.used_charge)
        instance.is_auto_xunhang =  validated_data.get('is_auto_xunhang', instance.is_auto_xunhang)
        instance.numbers = validated_data.get('numbers', instance.numbers)
        instance.maintenance_record = validated_data.get('maintenance_record', instance.maintenance_record)
        instance.other_info = validated_data.get('other_info', instance.other_info)
        instance.save()
        return instance

class ProjectSerializer(serializers.ModelSerializer):

    class Meta:
        model = project_info
        fields = ('id','project_name','project_area','project_sqaure','robot_id','project_people','is_arrives',
        'regist_env','zeno_alias','usb_netcard_mac','is_power_on','trouble_shoot1','trouble_shoot2','trouble_shoot3',
        'trouble_shoot4','trouble_shoot5','trouble_shoot6','trouble_shoot7','trouble_shoot8','trouble_shoot9',
        'is_can_using','elevator_number','elevator_change','charge_loc','xunjiain_lianjie','guard_ac_number',
        'daily_rep_num','map_routeid', 'robot_dt_lianddong','routineid','tryrun','sucai_up','warning_up',
        'daily_rep_up_kehu','is_jiaojie','peixun_kehu','duijie_people','phone_num','live_area','file_url','other_info')


class ImageUploadSerializer(serializers.ModelSerializer):
    robot_id_id = serializers.CharField()
    image = serializers.ImageField()
    class Meta:
        model = Image
        fields=('robot_id_id','image')

class FaqImageUploadSerializer(serializers.ModelSerializer):

    class Meta:
        model = faq_image
        fields=('id','problem_id_id','image',)

class FaqSerializer(serializers.ModelSerializer):

    class Meta:
        model = faq
        fields=('id','problem','problem_solution','release_time','publisher')

class RoboxTipsSerializer(serializers.ModelSerializer):
    class Meta:
        model=robox_infoTips
        fields=('id','tips')


class ProjectTipsSerializer(serializers.ModelSerializer):
    class Meta:
        model=project_infoTips
        fields=('id','tips')

class RobotVersionSerializer(serializers.ModelSerializer):
    class Meta:
        model=robot_version
        fields=('id','big_version','robox','nimbo_app','slam','ros','android_us',
            'android_cn','ios_us','ios_cn','ios_guru','others')